<?php
session_start();
require("../funciones.php"); 
require("../funcionesDB.php"); 

if($_REQUEST['username']=='' && $_REQUEST['password']=='') {
	header("Location:login.php?usrerror=Y&pwderror=Y");
} else if($_REQUEST['username']=='') {
	header("Location:login.php?usrerror=Y&password=".$_REQUEST['password']);
} else if($_REQUEST['password']=='') {
	header("Location:login.php?pwderror=Y&username=".$_REQUEST['username']);
} else {
	$userString = "select user_id from usuarios where usuario='".$_REQUEST['username']."' and password='".$_REQUEST['password']."'";
	$userQuery = dbSelect($userString) or die("Error en ".$userString." ".mysql_error());
	if ($userResult = mysql_fetch_array($userQuery)) {
		$_SESSION['user_id'] = $userResult['user_id'];
		$_SESSION['username'] = $_REQUEST['username'];
		header("Location:index.php");
	} else {
		header("Location:login.php?inxerror=Y&username=".$_REQUEST['username']."&password=".$_REQUEST['password']);
	} 
}

?>